package elsa.controller;

import elsa.bean.*;
import elsa.bootmapper.UserMapper;
import elsa.tools.*;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.codec.Hex;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.security.MessageDigest;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Controller
public class UserController {

    @Autowired
    private UserMapper userMapper;

    /*
     * 用户操作
     */
    //查看个人信息
    @CrossOrigin
    @RequestMapping(value = "/personal/info",method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("public")
    public ScsUser personalInfo(){
        Subject subject = SecurityUtils.getSubject();
        ScsUser scsUser =(ScsUser) subject.getPrincipal();
        String Role = userMapper.findRole(scsUser.getUserid()).getRole();
        switch (Role){
            case "管理员":
                ScsUser admin = userMapper.findGlyByUserid(scsUser.getUserid());
                admin.setRole(Role);
                return admin;
            case "负责人":
                ScsUser head = userMapper.findFzrByUserid(scsUser.getUserid());
                head.setRole(Role);
                return head;
            case "验船师":
                ScsUser surveyor = userMapper.findYcsByUserid(scsUser.getUserid());
                surveyor.setRole(Role);
                return surveyor;
            case "船厂":
                ScsUser shipyard = userMapper.findCcByUserid(scsUser.getUserid());
                shipyard.setRole(Role);
                return shipyard;
            case "船东":
                ScsUser shipowner = userMapper.findCdByUserid(scsUser.getUserid());
                shipowner.setRole(Role);
                return shipowner;
            default:
                return null;
        }
    }

    //查看个人角色
    @CrossOrigin
    @RequestMapping(value = "/personal/role",method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("public")
    public ScsRole personalRole(){
        Subject subject = SecurityUtils.getSubject();
        ScsUser scsUser =(ScsUser) subject.getPrincipal();
        return userMapper.findRole(scsUser.getUserid());
    }

    //修改密码
    @CrossOrigin
    @RequestMapping(value = "/personal/updatepsw",method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("public")
    public Message updatePsw(@RequestBody ScsUser userEntity){
        Subject subject = SecurityUtils.getSubject();
        ScsUser scsUser =(ScsUser) subject.getPrincipal();
        userEntity.setUsername(scsUser.getUsername());
        return new Message(setUpdatePsw(userEntity));
    }

    //修改用户信息
    @CrossOrigin
    @RequestMapping(value = "/personal/update",method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("public")
    public Message updateUser(@RequestBody ScsUser userEntity){
        Subject subject = SecurityUtils.getSubject();
        ScsUser scsUser =(ScsUser) subject.getPrincipal();
        userEntity.setUserid(scsUser.getUserid());
        return new Message(setUpdateUser(userEntity));
    }

    //禁用用户
    @CrossOrigin
    @RequestMapping(value = "/user/forbid/{userid}", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message forbidUser(@PathVariable("userid") String userid){
        return new Message(setForbidUser(userid));
    }

    //恢复用户
    @CrossOrigin
    @RequestMapping(value = "/user/renew/{userid}", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message renewUser(@PathVariable("userid") String userid){
        return new Message(setRenewUser(userid));
    }

    //重置密码
    @CrossOrigin
    @RequestMapping(value = "/user/reset/{userid}", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message resetUser(@PathVariable("userid") String userid){
        String b = "";
        if(userid==null||userid.equals("")||userMapper.findByUserid(userid)==null){
            b = "不存在该用户!";
        }else if(userMapper.findByUserid(userid).getState().equals("禁用")){
            b = "该用户已被禁用!";
        }else {
            String salt = userMapper.findByUserid(userid).getUsername();
            String password = md5Hex(salt+userid.substring(userid.length()-6, userid.length()));
            userMapper.resetPsw(password, userid);
            b = "重置成功!";
        }
        return new Message(b);
    }

    /*
     * 管理员操作
     */
    //查询所有管理员 兼 搜索 兼 分页
    @CrossOrigin
    @RequestMapping(value="/user/gly/all", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public MyResp userlistGly(@RequestParam("pageIndex") Integer pageIndex,
                              @RequestParam("pageSize") Integer pageSize,
                              @RequestParam(value="value",required = false,defaultValue = "null") String value,
                              @RequestParam(value="type",required = false,defaultValue = "null") String type){
        if(pageIndex==null){
            pageIndex=1;
        }
        if(pageSize==null){
            pageSize=10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        switch (type){
            case "Name":
                return  MyResp.render(0,"获取成功",userMapper.findGlyByName(value),userMapper.findGlyCountByName(value));
            case "phoneNum":
                return MyResp.render(0,"获取成功",userMapper.findGlyByUsername(value),userMapper.findGlyCountByUsername(value));
            case "Sex":
                return  MyResp.render(0,"获取成功",userMapper.findSexGly(value),userMapper.findSexGlyCount(value));
            case "State":
                return MyResp.render(0,"获取成功",userMapper.findStateGly(value),userMapper.findStateGlyCount(value));
            case "":
                return MyResp.render(0,"获取成功",userMapper.findAllGly(),userMapper.findGlyCount());
            default:
                return MyResp.render(0,"获取成功",userMapper.findAllGly(),userMapper.findGlyCount());
        }
    }

    //查询管理员用户(身份证号)
    @CrossOrigin
    @RequestMapping(value="/user/gly/{userid}", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public ScsUser findGlyByUsername(@PathVariable("userid") String userid){
        if(userid==null){
            userid="";
        }
        return userMapper.findGlyByUserid(userid);
    }

    //查询管理员列表
    @CrossOrigin
    @RequestMapping(value="/user/gly", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public List<ScsUser> userlistGly(){
        return  userMapper.findAllGly();
    }

    //新增管理员用户
    @CrossOrigin
    @RequestMapping(value = "/user/gly/new",method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message addGly(@RequestBody ScsUser userEntity){
        return new Message(setAddGly(userEntity));
    }

    //更新管理员用户
    @CrossOrigin
    @RequestMapping(value = "/user/gly/update", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message updateGly(@RequestBody ScsUser userEntity){
        return new Message(setUpdateGly(userEntity));
    }

    //删除管理员
    @CrossOrigin
    @RequestMapping(value = "/user/gly/{userid}", method = RequestMethod.DELETE)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message deleteGly(@PathVariable("userid") String userid){
        return new Message(setDeleteGly(userid));
    }


    /*
     * 负责人操作
     */
    //查询所有负责人 兼 搜索 兼 分页
    @CrossOrigin
    @RequestMapping(value="/user/fzr/all", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public MyResp userlistFzr(@RequestParam("pageIndex") Integer pageIndex,
                              @RequestParam("pageSize") Integer pageSize,
                              @RequestParam(value="value",required = false,defaultValue = "null") String value,
                              @RequestParam(value="type",required = false,defaultValue = "null") String type){
        if(pageIndex==null){
            pageIndex=1;
        }
        if(pageSize==null){
            pageSize=10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        switch (type){
            case "Name":
                return  MyResp.render(0,"获取成功",userMapper.findFzrByName(value),userMapper.findFzrCountByName(value));
            case "phoneNum":
                return MyResp.render(0,"获取成功",userMapper.findFzrByUsername(value),userMapper.findFzrCountByUsername(value));
            case "Sex":
                return  MyResp.render(0,"获取成功",userMapper.findSexFzr(value),userMapper.findSexFzrCount(value));
            case "State":
                return MyResp.render(0,"获取成功",userMapper.findStateFzr(value),userMapper.findStateFzrCount(value));
            case "":
                return MyResp.render(0,"获取成功",userMapper.findAllFzr(),userMapper.findFzrCount());
            default:
                return MyResp.render(0,"获取成功",userMapper.findAllFzr(),userMapper.findFzrCount());
        }
    }

    //查询负责人用户(身份证号)
    @CrossOrigin
    @RequestMapping(value="/user/fzr/{userid}", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public ScsUser findFzrByUsername(@PathVariable("userid") String userid){
        if(userid==null){
            userid="";
        }
        return userMapper.findFzrByUserid(userid);
    }

    //查询负责人列表
    @CrossOrigin
    @RequestMapping(value="/user/fzr", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public List<ScsUser> userlistFzr(){
        return  userMapper.findAllFzr();
    }

    //新增负责人用户
    @CrossOrigin
    @RequestMapping(value = "/user/fzr/new",method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message addFzr(@RequestBody ScsUser userEntity){
        return new Message(setAddFzr(userEntity));
    }

    //更新负责人用户
    @CrossOrigin
    @RequestMapping(value = "/user/fzr/update", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message updateFzr(@RequestBody ScsUser userEntity){
        return new Message(setUpdateFzr(userEntity));
    }

    //删除负责人
    @CrossOrigin
    @RequestMapping(value = "/user/fzr/{userid}", method = RequestMethod.DELETE)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message deleteFzr(@PathVariable("userid") String userid){
        return new Message(setDeleteFzr(userid));
    }


    /*
	 * 验船师操作
	 */
    //查询验船师列表 兼 搜索 兼 分页
    @CrossOrigin
    @RequestMapping(value="/user/ycs/all", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public MyResp userlistYcs(@RequestParam("pageIndex") Integer pageIndex,
                              @RequestParam("pageSize") Integer pageSize,
                              @RequestParam(value="value",required = false,defaultValue = "null") String value,
                              @RequestParam(value="type",required = false,defaultValue = "null") String type){
        if(pageIndex==null){
            pageIndex=1;
        }
        if(pageSize==null){
            pageSize=10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        switch (type){
            case "Name":
                return  MyResp.render(0,"获取成功",userMapper.findYcsByName(value),userMapper.findYcsCountByName(value));
            case "phoneNum":
                return MyResp.render(0,"获取成功",userMapper.findYcsByUsername(value),userMapper.findYcsCountByUsername(value));
            case "Sex":
                return  MyResp.render(0,"获取成功",userMapper.findSexYcs(value),userMapper.findSexYcsCount(value));
            case "State":
                return MyResp.render(0,"获取成功",userMapper.findStateYcs(value),userMapper.findStateYcsCount(value));
            case "ct":
                return MyResp.render(0,"获取成功",userMapper.findCtYcs(value),userMapper.findCtYcsCount(value));
            case "lj":
                return MyResp.render(0,"获取成功",userMapper.findLjYcs(value),userMapper.findLjYcsCount(value));
            case "dq":
                return MyResp.render(0,"获取成功",userMapper.findDqYcs(value),userMapper.findDqYcsCount(value));
            case "":
                return MyResp.render(0,"获取成功",userMapper.findAllYcs(),userMapper.findYcsCount());
            default:
                return MyResp.render(0,"获取成功",userMapper.findAllYcs(),userMapper.findYcsCount());
        }
    }

    //查询验船师用户(身份证号)
    @CrossOrigin
    @RequestMapping(value="/user/ycs/{userid}", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public ScsUser findYcsByUsername(@PathVariable("userid") String userid){
        if(userid==null){
            userid="";
        }
        return userMapper.findYcsByUserid(userid);
    }

    //查询验船师列表
    @CrossOrigin
    @RequestMapping(value="/user/ycs", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("public")
    public List<ScsUser> userlistYcs(@RequestParam(value="value",required = false,defaultValue = "null") String value,
                                         @RequestParam(value="type",required = false,defaultValue = "null") String type){
        switch (type){
            case "ct":
                return userMapper.findCtYcs(value);
            case "lj":
                return userMapper.findLjYcs(value);
            case "dq":
                return userMapper.findDqYcs(value);
            default:
                return  userMapper.findAllYcs();
        }
    }

    //新增验船师用户
    @CrossOrigin
    @RequestMapping(value = "/user/ycs/new",method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message addYcs(@RequestBody ScsUser userEntity){
        return new Message(setAddYcs(userEntity));
    }

    //更新验船师用户
    @CrossOrigin
    @RequestMapping(value = "/user/ycs/update", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message updateYcs(@RequestBody ScsUser userEntity){
        return new Message(setUpdateYcs(userEntity));
    }

    //删除验船师
    @CrossOrigin
    @RequestMapping(value = "/user/ycs/{userid}", method = RequestMethod.DELETE)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message deleteYcs(@PathVariable("userid") String userid){
        return new Message(setDeleteYcs(userid));
    }


    /*
     * 船厂用户操作
     */
    //查询船厂用户列表 兼 搜索 兼 分页
    @CrossOrigin
    @RequestMapping(value="/user/cc/all", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public MyResp userlistCc(@RequestParam("pageIndex") Integer pageIndex,
                             @RequestParam("pageSize") Integer pageSize,
                             @RequestParam(value="value",required = false,defaultValue = "null") String value,
                             @RequestParam(value="type",required = false,defaultValue = "null") String type){
        if(pageIndex==null){
            pageIndex=1;
        }
        if(pageSize==null){
            pageSize=10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        switch (type){
            case "Name":
                return  MyResp.render(0,"获取成功",userMapper.findCcByName(value),userMapper.findCcCountByName(value));
            case "phoneNum":
                return MyResp.render(0,"获取成功",userMapper.findCcByUsername(value),userMapper.findCcCountByUsername(value));
            case "Sex":
                return  MyResp.render(0,"获取成功",userMapper.findSexCc(value),userMapper.findSexCcCount(value));
            case "State":
                return MyResp.render(0,"获取成功",userMapper.findStateCc(value),userMapper.findStateCcCount(value));
            case "Address":
                return MyResp.render(0,"获取成功",userMapper.findConameCc(value),userMapper.findConameCcCount(value));
            case "":
                return MyResp.render(0,"获取成功",userMapper.findAllCc(),userMapper.findCcCount());
            default:
                return MyResp.render(0,"获取成功",userMapper.findAllCc(),userMapper.findCcCount());
        }
    }

    //查询船厂用户(身份证)
    @CrossOrigin
    @RequestMapping(value="/user/cc/{userid}", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public ScsUser findCcByUserid(@PathVariable("userid") String userid){
        if(userid==null){
            userid="";
        }
        return userMapper.findCcByUserid(userid);
    }

    //查询船厂用户(用户名)
    @CrossOrigin
    @RequestMapping(value="/user/ccinfo/{username}", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions(value = {"admin","shipowner"},logical= Logical.OR)
    public ScsUser findCcByUsername(@PathVariable("username") String username){
        if(username==null){
            username="";
        }
        return userMapper.findCcinfoByUsername(username);
    }

    //查询船厂用户列表
    @CrossOrigin
    @RequestMapping(value="/user/cc", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions(value = {"admin","shipowner"},logical= Logical.OR)
    public List<ScsUser> userlistCc(){
        return  userMapper.findAllCc();
    }

    //新增船厂用户
    @CrossOrigin
    @RequestMapping(value = "/user/cc/new",method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message addCc(@RequestBody ScsUser userEntity){
        return new Message(setAddCc(userEntity));
    }

    //更新船厂用户
    @CrossOrigin
    @RequestMapping(value = "/user/cc/update", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message updateCc(@RequestBody ScsUser userEntity){
        return new Message(setUpdateCc(userEntity));
    }

    //删除船厂用户
    @CrossOrigin
    @RequestMapping(value = "/user/cc/{userid}", method = RequestMethod.DELETE)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message deleteCc(@PathVariable("userid") String userid){
        return new Message(setDeleteCc(userid));
    }


    /*
     * 船东操作
     */
    //查询船东列表 兼 搜索 兼 分页
    @CrossOrigin
    @RequestMapping(value="/user/cd/all", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public MyResp userlistCd(@RequestParam("pageIndex") Integer pageIndex,
                             @RequestParam("pageSize") Integer pageSize,
                             @RequestParam(value="value",required = false,defaultValue = "null") String value,
                             @RequestParam(value="type",required = false,defaultValue = "null") String type){
        if(pageIndex==null){
            pageIndex=1;
        }
        if(pageSize==null){
            pageSize=10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        switch (type){
            case "Name":
                return  MyResp.render(0,"获取成功",userMapper.findCdByName(value),userMapper.findCdCountByName(value));
            case "phoneNum":
                return MyResp.render(0,"获取成功",userMapper.findCdByUsername(value),userMapper.findCdCountByUsername(value));
            case "Sex":
                return  MyResp.render(0,"获取成功",userMapper.findSexCd(value),userMapper.findSexCdCount(value));
            case "State":
                return MyResp.render(0,"获取成功",userMapper.findStateCd(value),userMapper.findStateCdCount(value));
            case "":
                return MyResp.render(0,"获取成功",userMapper.findAllCd(),userMapper.findCdCount());
            default:
                return MyResp.render(0,"获取成功",userMapper.findAllCd(),userMapper.findCdCount());
        }
    }

    //查询船东用户(用户名)
    @CrossOrigin
    @RequestMapping(value="/user/cd/{userid}", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("admin")
    public ScsUser findCdByUsername(@PathVariable("userid") String userid){
        if(userid==null){
            userid="";
        }
        return userMapper.findCdByUserid(userid);
    }

    //查询船东列表
    @CrossOrigin
    @RequestMapping(value="/user/cd", method = RequestMethod.GET)
    @ResponseBody
    @RequiresPermissions("public")
    public List<ScsUser> userlistCd(){
        return  userMapper.findAllCd();
    }

    //新增船东用户
    @CrossOrigin
    @RequestMapping(value = "/user/cd/new",method = RequestMethod.POST)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message addCd(@RequestBody ScsUser userEntity){
        return new Message(setAddCd(userEntity));
    }

    //更新船东用户
    @CrossOrigin
    @RequestMapping(value = "/user/cd/update", method = RequestMethod.PUT)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message updateCd(@RequestBody ScsUser userEntity){
        return new Message(setUpdateCd(userEntity));
    }

    //删除船东
    @CrossOrigin
    @RequestMapping(value = "/user/cd/{userid}", method = RequestMethod.DELETE)
    @ResponseBody
    @RequiresPermissions("admin")
    public Message deleteCd(@PathVariable("userid") String userid){
        return new Message(setDeleteCd(userid));
    }

//    //船东信息
//    @CrossOrigin
//    @RequestMapping(value="/user/cd/info", method = RequestMethod.GET)
//    @ResponseBody
//    @RequiresPermissions("admin")
//    public List<ScsUser> getCdInfo(){
//        return userMapper.findCdInfo();
//    }


    /*
     * 基本操作
     */
    //修改用户信息
    private String setUpdateUser(ScsUser userEntity){
        String b;
        String role = userMapper.findRole(userEntity.getUserid()).getRole();
        switch (role){
            case "管理员":
                if (userEntity.getName()==null||!chickName(userEntity.getName())) {
                    b = "姓名格式错误!";
                }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
                    b = "性别格式错误!";
                }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
                    b = "手机号码格式错误!";
                }else if (!userEntity.getUsername().equals(userMapper.findGlyByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
                    b = "该手机号已被注册!";
                }else{
                    userMapper.updateUser(userEntity);
                    userMapper.updateGly(userEntity);
                    b = "用户修改成功!";
                }
                break;
            case "负责人":
                if (userEntity.getName()==null||!chickName(userEntity.getName())) {
                    b = "姓名格式错误!";
                }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
                    b = "性别格式错误!";
                }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
                    b = "手机号码格式错误!";
                }else if (!userEntity.getUsername().equals(userMapper.findFzrByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
                    b = "该手机号已被注册!";
                }else{
                    userMapper.updateUser(userEntity);
                    userMapper.updateFzr(userEntity);
                    b = "用户修改成功!";
                }
                break;
            case "验船师":
                if (userEntity.getName()==null||!chickName(userEntity.getName())) {
                    b = "姓名格式错误!";
                }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
                    b = "性别格式错误!";
                }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
                    b = "手机号码格式错误!";
                }else if (!userEntity.getUsername().equals(userMapper.findYcsByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
                    b = "该手机号已被注册!";
                }else if (userEntity.getCt()==null||userEntity.getLj()==null||userEntity.getDq()==null||!chickWorkarea(userEntity.getCt(), userEntity.getLj(), userEntity.getDq())) {
                    b = "负责领域格式错误!";
                }else{
//                    if(!userMapper.findYcsByUserid(userEntity.getUserid()).getUsername().equals(userEntity.getUsername())||!userMapper.findYcsByUserid(userEntity.getUserid()).getName().equals(userEntity.getName())){
//                        String oldusername = userMapper.findYcsByUserid(userEntity.getUserid()).getUsername();
//                        String oldname = userMapper.findYcsByUserid(userEntity.getUserid()).getName();
//                        String newusername = userEntity.getUsername();
//                        String newname = userEntity.getName();
//                    }
                    userMapper.updateUser(userEntity);
                    userMapper.updateYcs(userEntity);
                    b = "用户修改成功!";
                }
                break;
            case "船厂":
                if (userEntity.getName()==null||!chickName(userEntity.getName())) {
                    b = "姓名格式错误!";
                }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
                    b = "性别格式错误!";
                }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
                    b = "手机号码格式错误!";
                }else if (!userEntity.getUsername().equals(userMapper.findCcByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
                    b = "该手机号已被注册!";
                }else if (userEntity.getConame()==null||!chickCcConame(userEntity.getConame())) {
                    b = "企业名称格式错误!";
                }else if (userEntity.getUsername()==null||!chickFax(userEntity.getFax())){
                    b = "传真格式错误!";
                }else if (userEntity.getZipcode()==null||!chickZipcode(userEntity.getZipcode())){
                    b = "邮编格式错误!";
                }else if (userEntity.getCrecode()==null||!chickCrecode(userEntity.getCrecode())){
                    b = "社会统一代码格式错误!";
                }else if (userEntity.getCcadr()==null||!chickCcadr(userEntity.getCcadr())){
                    b = "地址格式错误!";
                }else if (userEntity.getWritename()==null||!chickName(userEntity.getWritename())){
                    b = "负责人格式错误!";
                }else {
//                    if(!userMapper.findCcByUserid(userEntity.getUserid()).getUsername().equals(userEntity.getUsername())||!userMapper.findCcByUserid(userEntity.getUserid()).getName().equals(userEntity.getName())){
//                        String oldinfo = userMapper.findCcByUserid(userEntity.getUserid()).getName()+"/"+userMapper.findCcByUserid(userEntity.getUserid()).getUsername();
//                        String newinfo = userEntity.getName()+"/"+userEntity.getUsername();
//                    }
                    userMapper.updateUser(userEntity);
                    userMapper.updateCc(userEntity);
                    b = "用户修改成功!";
                }
                break;
            case "船东":
                if (userEntity.getName()==null||!chickName(userEntity.getName())) {
                    b = "姓名格式错误!";
                }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
                    b = "性别格式错误!";
                }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
                    b = "手机号码格式错误!";
                }else if (!userEntity.getUsername().equals(userMapper.findCdByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
                    b = "该手机号已被注册!";
                }else if (userEntity.getConame()==null||!chickCdConame(userEntity.getConame())) {
                    b = "企业名称格式错误!";
                }else{
//                    if(!userMapper.findCdByUserid(userEntity.getUserid()).getUsername().equals(userEntity.getUsername())||!userMapper.findCdByUserid(userEntity.getUserid()).getName().equals(userEntity.getName())){
//                        String oldusername = userMapper.findCdByUserid(userEntity.getUserid()).getUsername();
//                        String oldname = userMapper.findCdByUserid(userEntity.getUserid()).getName();
//                        String newusername = userEntity.getUsername();
//                        String newname = userEntity.getName();
//                    }
                    userMapper.updateUser(userEntity);
                    userMapper.updateCd(userEntity);
                    b = "用户修改成功!";
                }
                break;
            default:
                b = "用户修改失败!";
        }
        return b;
    }

    //修改密码
    private String setUpdatePsw(ScsUser userEntity){
        String b;
        if(userEntity.getUsername()==null||userMapper.findByUsername(userEntity.getUsername())==null){
            b = "该用户名不存在!";
        }else if (userEntity.getPassword()==null||!chickPassword(userEntity.getPassword())) {
            b = "密码格式错误!";
        }else if(userEntity.getOldpsd()==null||!md5Hex(userEntity.getUsername()+userEntity.getOldpsd()).equals(userMapper.findByUsername(userEntity.getUsername()).getPassword())){
            b = "旧密码错误!";
        }else {
            userEntity.setPassword(md5Hex(userEntity.getUsername()+userEntity.getPassword()));
            userMapper.updatePsw(userEntity);
            b = "密码修改成功!";
        }
        return b;
    }

    //禁用用户
    private String setForbidUser(String userid){
        String b;
        if(userid==null||userMapper.findByUserid(userid)==null){
            b = "该用户不存在!";
        }else if (userMapper.findByUserid(userid).getState().equals("禁用")) {
            b = "请勿重复操作!";
        }else {
            userMapper.forbidUser(userid);
            b = "禁用成功!";
        }
        return b;
    }

    //恢复用户
    private String setRenewUser(String userid){
        String b;
        if(userid==null||userMapper.findByUserid(userid)==null){
            b = "该用户不存在!";
        }else if (userMapper.findByUserid(userid).getState().equals("正常")) {
            b = "请勿重复操作!";
        }else {
            userMapper.renewUser(userid);
            b = "恢复成功!";
        }
        return b;
    }

    //新增管理员用户
    private String setAddGly(ScsUser userEntity){
        String b;
        if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "请正确填写手机号码!";
        }else if(userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())){
            b = "请正确填写身份证!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "请正确填写姓名!";
        }else if(userEntity.getSex()==null||!chickSex(userEntity.getSex())){
            b = "请正确填写性别!";
        }else if(userMapper.findByUsername(userEntity.getUsername())!=null){
            b = "手机号码已存在!";
        }else if (userMapper.findByUserid(userEntity.getUserid())!=null) {
            b = "此身份证已被注册!";
        }else {
            String id = userEntity.getUserid();
            String salt = userEntity.getUsername();
            userEntity.setPassword(md5Hex(salt+id.substring(id.length()-6, id.length())));
            userEntity.setState("正常");
            userEntity.setLatesttime(getNtime());
            userEntity.setRgsttime(getNtime());
            ScsRole scsRole = new ScsRole();
            scsRole.setUserid(userEntity.getUserid());
            scsRole.setRole("管理员");
            userMapper.saveRole(scsRole);
            userMapper.saveUser(userEntity);
            userMapper.saveGly(userEntity);
            b = "管理员用户创建成功!";
        }
        return b;
    }

    //更新管理员用户
    private String setUpdateGly(ScsUser userEntity){
        String b;
        if (userEntity.getUserid()!=null&&userMapper.findByUserid(userEntity.getUserid()).getState().equals("禁用")) {
            b = "该用户已被禁用!";
        }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "手机号码格式错误!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "姓名格式错误!";
        }else if (userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())) {
            b = "身份证格式错误!";
        }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
            b = "性别格式错误!";
        }else if (!userEntity.getUsername().equals(userMapper.findGlyByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
            b = "该手机号已被注册!";
        }else if (userMapper.findGlyByUserid(userEntity.getUserid())==null) {
            b = "该用户不存在!";
        }else {
            userMapper.updateUser(userEntity);
            userMapper.updateGly(userEntity);
            b = "管理员用户更新成功!";
        }
        return b;
    }

    //删除管理员
    private String setDeleteGly(String userid){
        String b = "管理员用户删除失败!";
        if(userid!=null&&userMapper.findByUserid(userid)!=null){
            userMapper.deleteGly(userid);
            userMapper.delete(userid);
            userMapper.deleteRole(userid);
            b = "管理员用户删除成功!";
        }
        return b;
    }

    //新增负责人用户
    private String setAddFzr(ScsUser userEntity){
        String b;
        if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "请正确填写手机号码!";
        }else if(userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())){
            b = "请正确填写身份证!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "请正确填写姓名!";
        }else if(userEntity.getSex()==null||!chickSex(userEntity.getSex())){
            b = "请正确填写性别!";
        }else if(userMapper.findByUsername(userEntity.getUsername())!=null){
            b = "手机号码已存在!";
        }else if (userMapper.findByUserid(userEntity.getUserid())!=null) {
            b = "此身份证已被注册!";
        }else {
            String id = userEntity.getUserid();
            String salt = userEntity.getUsername();
            userEntity.setPassword(md5Hex(salt+id.substring(id.length()-6, id.length())));
            userEntity.setState("正常");
            userEntity.setLatesttime(getNtime());
            userEntity.setRgsttime(getNtime());
            ScsRole scsRole = new ScsRole();
            scsRole.setUserid(userEntity.getUserid());
            scsRole.setRole("负责人");
            userMapper.saveRole(scsRole);
            userMapper.saveUser(userEntity);
            userMapper.saveFzr(userEntity);
            b = "负责人用户创建成功!";
        }
        return b;
    }

    //更新负责人用户
    private String setUpdateFzr(ScsUser userEntity){
        String b;
        if (userEntity.getUserid()!=null&&userMapper.findByUserid(userEntity.getUserid()).getState().equals("禁用")) {
            b = "该用户已被禁用!";
        }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "手机号码格式错误!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "姓名格式错误!";
        }else if (userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())) {
            b = "身份证格式错误!";
        }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
            b = "性别格式错误!";
        }else if (!userEntity.getUsername().equals(userMapper.findFzrByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
            b = "该手机号已被注册!";
        }else if (userMapper.findFzrByUserid(userEntity.getUserid())==null) {
            b = "该用户不存在!";
        }else {
            userMapper.updateUser(userEntity);
            userMapper.updateFzr(userEntity);
            b = "负责人用户更新成功!";
        }
        return b;
    }

    //删除负责人
    private String setDeleteFzr(String userid){
        String b = "负责人用户删除失败!";
        if(userid!=null&&userMapper.findByUserid(userid)!=null){
            userMapper.deleteFzr(userid);
            userMapper.delete(userid);
            userMapper.deleteRole(userid);
            b = "负责人用户删除成功!";
        }
        return b;
    }

    //新增验船师用户
    private String setAddYcs(ScsUser userEntity){
        String b;
        if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "请正确填写手机号码!";
        }else if(userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())){
            b = "请正确填写身份证!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "请正确填写姓名!";
        }else if(userEntity.getSex()==null||!chickSex(userEntity.getSex())){
            b = "请正确填写性别!";
        }else if (userEntity.getCt()==null||userEntity.getLj()==null||userEntity.getDq()==null||!chickWorkarea(userEntity.getCt(), userEntity.getLj(), userEntity.getDq())) {
            b = "请选择负责领域!";
        }else if(userMapper.findByUsername(userEntity.getUsername())!=null){
            b = "手机号码已存在!";
        }else if (userMapper.findByUserid(userEntity.getUserid())!=null) {
            b = "此身份证已被注册！";
        }else {
            String id = userEntity.getUserid();
            String salt = userEntity.getUsername();
            userEntity.setPassword(md5Hex(salt+id.substring(id.length()-6, id.length())));
            userEntity.setState("正常");
            userEntity.setLatesttime(getNtime());
            userEntity.setRgsttime(getNtime());
            ScsRole scsRole = new ScsRole();
            scsRole.setUserid(userEntity.getUserid());
            scsRole.setRole("验船师");
            userMapper.saveRole(scsRole);
            userMapper.saveUser(userEntity);
            userMapper.saveYcs(userEntity);
            b = "验船师用户创建成功!";
        }
        return b;
    }

    //更新验船师用户
    private String setUpdateYcs(ScsUser userEntity){
        String b;
        if (userEntity.getUsername()!=null&&userMapper.findByUserid(userEntity.getUserid()).getState().equals("禁用")) {
            b = "该用户已被禁用!";
        }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "用户名格式错误!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "姓名格式错误!";
        }else if (userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())) {
            b = "身份证格式错误!";
        }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
            b = "性别格式错误!";
        }else if (!userEntity.getUsername().equals(userMapper.findYcsByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
            b = "该手机号已被注册!";
        }else if (userEntity.getCt()==null||userEntity.getLj()==null||userEntity.getDq()==null||!chickWorkarea(userEntity.getCt(), userEntity.getLj(), userEntity.getDq())) {
            b = "负责领域格式错误!";
        }else if (userMapper.findYcsByUserid(userEntity.getUserid())==null) {
            b = "该用户不存在!";
        }else {
            userMapper.updateUser(userEntity);
            userMapper.updateYcs(userEntity);
            b = "验船师用户更新成功!";
        }
        return b;
    }

    //删除验船师
    private String setDeleteYcs(String userid){
        String b;
        if(userid==null||userMapper.findByUserid(userid)==null){
            b = "验船师用户删除失败!";
        }else if(userMapper.findYcsByUserid(userid).getWork()!=0){
            b = "此用户正在参与项目，不能删除!";
        }else {
            userMapper.deleteYcs(userid);
            userMapper.delete(userid);
            userMapper.deleteRole(userid);
            b = "验船师用户删除成功!";
        }
        return b;
    }

    //新增船厂用户
    private String setAddCc(ScsUser userEntity){
        String b;
        if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "请正确填写手机号码!";
        }else if(userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())){
            b = "请正确填写身份证!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "请正确填写姓名!";
        }else if(userEntity.getSex()==null||!chickSex(userEntity.getSex())){
            b = "请正确填写性别!";
        }else if (userEntity.getConame()==null||!chickCcConame(userEntity.getConame())){
            b = "请正确填写企业名称!";
        }else if (userEntity.getFax()==null||!chickFax(userEntity.getFax())){
            b = "请正确填写传真格式!";
        }else if (userEntity.getZipcode()==null||!chickZipcode(userEntity.getZipcode())){
            b = "请正确填写邮编格式!";
        }else if (userEntity.getCrecode()==null||!chickCrecode(userEntity.getCrecode())){
            b = "请正确填写社会统一代码格式!";
        }else if (userEntity.getCcadr()==null||!chickCcadr(userEntity.getCcadr())){
            b = "请正确填写地址!";
        }else if (userEntity.getWritename()==null||!chickWritename(userEntity.getWritename())){
            b = "请正确填写负责人!";
        }else if(userMapper.findByUsername(userEntity.getUsername())!=null){
            b = "手机号码已存在!";
        }else if (userMapper.findByUserid(userEntity.getUserid())!=null) {
            b = "此身份证已被注册!";
        }else {
            String id = userEntity.getUserid();
            String salt = userEntity.getUsername();
            userEntity.setPassword(md5Hex(salt+id.substring(id.length()-6, id.length())));
            userEntity.setState("正常");
            userEntity.setLatesttime(getNtime());
            userEntity.setRgsttime(getNtime());
            ScsRole scsRole = new ScsRole();
            scsRole.setUserid(userEntity.getUserid());
            scsRole.setRole("船厂");
            userMapper.saveRole(scsRole);
            userMapper.saveUser(userEntity);
            userMapper.saveCc(userEntity);
            b = "船厂用户创建成功!";
        }
        return b;
    }

    //更新船厂用户
    private String setUpdateCc(ScsUser userEntity){
        String b;
        if (userEntity.getUsername()!=null&&userMapper.findByUserid(userEntity.getUserid()).getState().equals("禁用")) {
            b = "该用户已被禁用!";
        }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "用户名格式错误!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "姓名格式错误!";
        }else if (userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())) {
            b = "身份证格式错误!";
        }else if (userEntity.getSex()==null||!chickSex(userEntity.getSex())) {
            b = "性别格式错误!";
        }else if (!userEntity.getUsername().equals(userMapper.findCcByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
            b = "该手机号已被注册!";
        }else if (userEntity.getConame()==null||!chickCcConame(userEntity.getConame())) {
            b = "企业名称格式错误!";
        }else if (userEntity.getFax()==null||!chickFax(userEntity.getFax())){
            b = "传真格式错误!";
        }else if (userEntity.getZipcode()==null||!chickZipcode(userEntity.getZipcode())){
            b = "邮编格式错误!";
        }else if (userEntity.getCrecode()==null||!chickCrecode(userEntity.getCrecode())){
            b = "社会统一代码格式错误!";
        }else if (userEntity.getCcadr()==null||!chickCcadr(userEntity.getCcadr())){
            b = "地址格式错误!";
        }else if (userEntity.getWritename()==null||!chickWritename(userEntity.getWritename())){
            b = "负责人格式错误!";
        }else if (userMapper.findCcByUserid(userEntity.getUserid())==null) {
            b = "该用户不存在!";
        }else {
            userMapper.updateUser(userEntity);
            userMapper.updateCc(userEntity);
            b = "船厂用户更新成功!";
        }
        return b;
    }

    //删除船厂用户
    private String setDeleteCc(String userid){
        String b;
        if(userid==null||userMapper.findByUserid(userid)==null){
            b = "船厂用户删除失败!";
        }else if(userMapper.findCcByUserid(userid).getWork()!=0){
            b = "此用户正在参与项目，不能删除!";
        }else {
            userMapper.deleteCc(userid);
            userMapper.delete(userid);
            userMapper.deleteRole(userid);
            b = "船厂用户删除成功!";
        }
        return b;
    }

    //新增船东用户
    private String setAddCd(ScsUser userEntity){
        String b;
        if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "请正确填写手机号码!";
        }else if(userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())){
            b = "请正确填写身份证!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "请正确填写姓名!";
        }else if(userEntity.getSex()==null||!chickSex(userEntity.getSex())){
            b = "请正确填写性别!";
        }else if (userEntity.getConame()==null||!chickCdConame(userEntity.getConame())) {
            b = "请正确填写企业名称!";
        }else if(userMapper.findByUsername(userEntity.getUsername())!=null){
            b = "手机号码已存在!";
        }else if (userMapper.findByUserid(userEntity.getUserid())!=null) {
            b = "此身份证已被注册!";
        }else {
            String id = userEntity.getUserid();
            userEntity.setPassword(id.substring(id.length()-6, id.length()));
            String salt = userEntity.getUsername();
            ScsUser scsUser = new ScsUser();
            scsUser.setUsername(userEntity.getUsername());
            scsUser.setPassword(md5Hex(salt+userEntity.getPassword()));
            scsUser.setUserid(userEntity.getUserid());
            scsUser.setState("正常");
            scsUser.setLatesttime(getNtime());
            ScsUser scsShipowner = new ScsUser();
            scsShipowner.setUserid(userEntity.getUserid());
            scsShipowner.setName(userEntity.getName());
            scsShipowner.setSex(userEntity.getSex());
            scsShipowner.setConame(userEntity.getConame());
            scsShipowner.setRgsttime(getNtime());
            ScsRole scsRole = new ScsRole();
            scsRole.setUserid(userEntity.getUserid());
            scsRole.setRole("船东");
            userMapper.saveRole(scsRole);
            userMapper.saveUser(scsUser);
            userMapper.saveCd(scsShipowner);
            b = "船东用户创建成功!";
        }
        return b;
    }

    //更新船东用户
    private String setUpdateCd(ScsUser userEntity){
        String b;
        if (userEntity.getUsername()!=null&&userMapper.findByUserid(userEntity.getUserid()).getState().equals("禁用")) {
            b = "该用户已被禁用!";
        }else if(userEntity.getUsername()==null||!chickUsername(userEntity.getUsername())){
            b = "用户名格式错误!";
        }else if (userEntity.getName()==null||!chickName(userEntity.getName())) {
            b = "姓名格式错误!";
        }else if (userEntity.getUserid()==null||!chickUserid(userEntity.getUserid())) {
            b = "身份证格式错误!";
        }else if (!userEntity.getUsername().equals(userMapper.findCdByUserid(userEntity.getUserid()).getUsername())&&userMapper.findByUsername(userEntity.getUsername())!=null) {
            b = "该手机号已被注册!";
        }else if (userEntity.getConame()==null||!chickCdConame(userEntity.getConame())) {
            b = "企业名称格式错误!";
        }else if (userMapper.findCdByUserid(userEntity.getUserid())==null) {
            b = "该用户不存在!";
        }else {
            ScsUser scsUser = new ScsUser();
            scsUser.setUsername(userEntity.getUsername());
            scsUser.setUserid(userEntity.getUserid());
            ScsUser scsShipowner = new ScsUser();
            scsShipowner.setUserid(userEntity.getUserid());
            scsShipowner.setName(userEntity.getName());
            scsShipowner.setSex(userEntity.getSex());
            scsShipowner.setConame(userEntity.getConame());
            userMapper.updateUser(scsUser);
            userMapper.updateCd(scsShipowner);
            b = "船东用户更新成功!";
        }
        return b;
    }

    //删除船东用户
    private String setDeleteCd(String userid){
        String b;
        if(userid==null||userMapper.findByUserid(userid)==null){
            b = "船东用户删除失败!";
        }else if(userMapper.findCdByUserid(userid).getWork()!=0){
            b = "此用户正在参与项目，不能删除!";
        }else {
            userMapper.deleteCd(userid);
            userMapper.delete(userid);
            userMapper.deleteRole(userid);
            b = "船东用户删除成功!";
        }
        return b;
    }


    /*
     * 其他操作
     */
    //加盐密码哈希
    private static String md5Hex(String src) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] bs = md5.digest(src.getBytes());
            new Hex();
            return new String(Hex.encode(bs));
        } catch (Exception e) {
            return null;
        }
    }

    //检验姓名
    private boolean chickName(String name){
        Pattern pattern = Pattern.compile("(^[\u4e00-\u9fa5]{2,4}$)|(^[a-zA-Z]{3,7}$)");
        Matcher match=pattern.matcher(name);
        return match.matches();
    }

    //检验密码
    private boolean chickPassword(String password){
        Pattern pattern = Pattern.compile("^[0-9A-Za-z]{6,12}$");
        Matcher match=pattern.matcher(password);
        return match.matches();
    }

    //检验性别
    private boolean chickSex(String sex){
        Boolean b = false;
        if(sex.equals("男")||sex.equals("女")){
            b = true;
        }
        return b;
    }

    //检验用户名
    private boolean chickUsername(String username){
        Pattern pattern = Pattern.compile("^1[345789]\\d{9}$");
        Matcher match=pattern.matcher(username);
        return match.matches();
    }

    //检验身份证
    private boolean chickUserid(String userid){
        Pattern pattern = Pattern.compile("^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|30|31)|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|X)$");
        Matcher match=pattern.matcher(userid);
        return match.matches();
    }

    //检验船厂企业名称
    private boolean chickCcConame(String coname){
        Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5\\(\\)\\（\\）]{2,20}$");
        Matcher match=pattern.matcher(coname);
        return match.matches();
    }

    //检验船东企业名称
    private boolean chickCdConame(String coname){
        Boolean b;
        if(!coname.equals("")){
            Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5\\(\\)\\（\\）]{2,20}$");
            Matcher match=pattern.matcher(coname);
            b = match.matches();
        }else{
            b = true;
        }
        return b;
    }

    //检验负责领域
    private boolean chickWorkarea(String ct, String lj, String dq){
        Boolean b = false;
        if((ct.equals("船体")||ct.equals(""))&&(lj.equals("轮机")||lj.equals(""))&&(dq.equals("电气")||dq.equals(""))){
            b = true;
        }
        if(ct.equals("")&&lj.equals("")&&dq.equals("")){
            b = false;
        }
        return b;
    }

    //检验传真格式
    private boolean chickFax(String fax){
        Boolean b;
        if(!fax.equals("")){
            Pattern pattern = Pattern.compile("^.{1,20}$");
            Matcher match=pattern.matcher(fax);
            b = match.matches();
        }else {
            b = true;
        }
        return b;
    }

    //检验邮编格式
    private boolean chickZipcode(String zipcode){
        Boolean b;
        if(!zipcode.equals("")){
            Pattern pattern = Pattern.compile("^.{1,20}$");
            Matcher match=pattern.matcher(zipcode);
            b = match.matches();
        }else {
            b = true;
        }
        return b;
    }

    //检验社会信用统一代码格式
    private boolean chickCrecode(String crecode){
        Pattern pattern = Pattern.compile("^[0-9A-Z]{18}$");
        Matcher match=pattern.matcher(crecode);
        return match.matches();
    }

    //检验船厂地址
    private boolean chickCcadr(String ccadr){
        Pattern pattern = Pattern.compile("^[\u4e00-\u9fa5\\(\\)\\（\\）A-Za-z0-9]{2,30}$");
        Matcher match=pattern.matcher(ccadr);
        return match.matches();
    }

    //检验负责人
    private boolean chickWritename(String writename){
        Boolean b;
        if(!writename.equals("")){
            Pattern pattern = Pattern.compile("(^[\u4e00-\u9fa5]{2,4}$)|(^[a-zA-Z]{3,7}$)");
            Matcher match=pattern.matcher(writename);
            b = match.matches();
        }else {
            b = true;
        }
        return b;
    }

    //获取当前时间
    private Date getNtime(){
        Date date = new Date();
        return new Timestamp(date.getTime());
    }
}
